$(function(){
    var totalPage= Math.ceil($("#totalPage").val()/10);
    if(totalPage>1){
        $('#Pagination').pagination(totalPage,{
            num_edge_entries: 2,
            num_display_entries: 4,
            items_per_page:1,
            prev_text:"上一页",
            next_text:"下一页",
            callback: function(currentPage){
                showList(currentPage+1)
            }
        })
    }
    function showList(currentPage){
        $.ajax({
            url: '/accountList',
            data: {
                pageStart: currentPage,
                pageSize: 10
            },
            type: 'get',
            typeDate: 'json',
            success: function(data){
                if(data.success){
                    if(data.count==0){
                        $('.accountList ul').html('<p style="padding-top: 50px; text-align: center; color: #999;">暂无数据</p>');
                    }else{
                        var htmlList = '';
                        var isEven = '';

                        for(var i=0;i<data.borrowAccountList.length;i++){
                            if(i%2==1){
                                isEven = 'even'
                            }else{
                                isEven=''
                            }
                            htmlList += '<li class="'+isEven+'">' +
                                '                        <a href="/detail/'+data.borrowAccountList[i].id+'">' +
                                '                            <span class="first">'+data.borrowAccountList[i].id+'</span>' +
                                '                            <span>'+data.borrowAccountList[i].statusNmae+'</span>' +
                                '                            <span>'+data.borrowAccountList[i].account+'</span>' +
                                '                            <span>'+data.borrowAccountList[i].waitPaymentAmount+'</span>' +
                                '                            <span>'+data.borrowAccountList[i].paymentAmount+'</span>' +
                                '                            <span class="last">'+data.borrowAccountList[i].interestEndTime+'</span>' +
                                '                        </a>' +
                                '                    </li>';
                        }
                        $('.accountList ul').empty().append(htmlList);
                    }
                }else{
                    $('.accountList ul').html('<p style="padding-top: 50px; text-align: center; color: #999;">'+data.msg+'</p>');
                }
            },
            error: function(){}
        })
    }
    showList(1);
});